package com.budwk.app.sqfwV2.generator.entrepreneurShipHouse;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.budwk.app.sqfwDoc.codeGeneratorV2.fileParam.CommonParam;
import com.budwk.app.sqfwDoc.codeGeneratorV2.fileParam.PdfGenerateParam;
import com.budwk.app.sqfwDoc.codeGeneratorV2.generate.BasePdfGenerator;
import com.budwk.app.sqfwV2.component.EntrepreneurShipHouseComponent;
import com.budwk.app.sqfwV2.component.SignImageComponent;
import com.budwk.app.sqfwV2.dto.dto.EntrepreneurShipHouseParamDTO;
import com.budwk.app.sqfwV2.enums.EntrepreneurHouseFileEnum;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * @author 东方祥云低代码1.1
 * @since 2024-04-26
 *
 * 创业实体入户 EntrepreneurShipHouse
 * 新增实体入户调查表.docx
 */
public class HouseholdSurveyFormDoc extends BasePdfGenerator{

    /**
    * 判断使用使用这个generator生成pdf
    *
    * @param pdfDTO 创建pdf数据素材
    * @return 结果
    */
    @Override
    public boolean pdfCreateConditionCheck(PdfGenerateParam pdfDTO) {
        EntrepreneurShipHouseParamDTO fieldDTO = (EntrepreneurShipHouseParamDTO) pdfDTO.getAbstractCustomerPdfCreateField();
        return true;
    }

    @Override
    public String getTemplatePath(PdfGenerateParam pdfGenerateParam) {
        return EntrepreneurHouseFileEnum.ONE_PDF.getFilePath();
    }

    @Override
    public void customerPopularPdfParam(Map<String, Object> map, PdfGenerateParam pdfGenerateParam) {
        // 在这里对一些数据进行填充 进行复杂的业务代码逻辑
        EntrepreneurShipHouseParamDTO param = (EntrepreneurShipHouseParamDTO) pdfGenerateParam.getAbstractCustomerPdfCreateField();
        map.put("placeName", EntrepreneurShipHouseComponent.formatStr(param.getPlaceName()));
        // 实体性质
        map.put("businessType", EntrepreneurShipHouseComponent.formatStr(param.getBusinessType()));
        // 所属产业
        map.put("belongingIndustry", EntrepreneurShipHouseComponent.formatStr(param.getBelongingIndustry()));
        // 所属行业
        map.put("industrySector", EntrepreneurShipHouseComponent.formatStr(param.getIndustrySector()));
        map.put("socialCreditCode", EntrepreneurShipHouseComponent.formatStr(param.getSocialCreditCode()));
        map.put("address", EntrepreneurShipHouseComponent.formatStr(param.getAddress()));
        // 注册日期
        map.put("businessRegistrationTime", LocalDateTimeUtil.format(param.getBusinessRegistrationTime(), DatePattern.CHINESE_DATE_PATTERN));
        // 经营范围
        map.put("mainBusinessScope", buildMainBussiness(param));
        // 经营者信息
        map.put("operator", EntrepreneurShipHouseComponent.formatStr(param.getOperator()));
        map.put("gender", param.getGender());
        map.put("age", EntrepreneurShipHouseComponent.NO_SUBMIT);
        if (param.getAge() != null) {
            map.put("age", param.getAge());
        }
        map.put("nation", EntrepreneurShipHouseComponent.formatStr(param.getNation()));
        map.put("educationalLevel", EntrepreneurShipHouseComponent.formatStr(param.getEducationalLevel()));
        // 毕业时间
        map.put("graduationTime", EntrepreneurShipHouseComponent.NO_SUBMIT);
        if (param.getGraduationTime() != null) {
            map.put("graduationTime", LocalDateTimeUtil.format(param.getGraduationTime(), DatePattern.CHINESE_DATE_PATTERN));
        }
        map.put("educationalLevel", EntrepreneurShipHouseComponent.formatStr(param.getEducationalLevel()));
        map.put("corporateIDNumber", EntrepreneurShipHouseComponent.formatStr(param.getCorporateIDNumber()));
        map.put("graduateSchool", EntrepreneurShipHouseComponent.formatStr(param.getGraduateSchool()));
        map.put("classMajor", EntrepreneurShipHouseComponent.formatStr(param.getClassMajor()));
        // 户籍性质
        map.put("houseRegistProperty", EntrepreneurShipHouseComponent.formatStr(param.getHouseRegistProperty()));
        map.put("houseRegistSituation", EntrepreneurShipHouseComponent.formatStr(param.getHouseRegistSituation()));
        map.put("householdAddress", EntrepreneurShipHouseComponent.formatStr(param.getHouseholdAddress()));
        map.put("permanentAddress", EntrepreneurShipHouseComponent.formatStr(param.getPermanentAddress()));
        map.put("operatorTelephone", EntrepreneurShipHouseComponent.formatStr(param.getOperatorTelephone()));
        map.put("jobNumber", param.getJobNumber() + "人");
        map.put("fillDate", LocalDateTimeUtil.format(param.getFillDate(), DatePattern.CHINESE_DATE_PATTERN));
        // 入户调查签名
        CommonParam commonParam = pdfGenerateParam.getCreateUserCommonParam();
        SignImageComponent.signWord(map, 1.5F, commonParam.getCreateUserSigUrl(), commonParam.getCreateUserName(), "checkedUnitLeader", "checkedUnitLeaderStr");
    }

    public static String buildMainBussiness(EntrepreneurShipHouseParamDTO param) {
        String mainBusinessScope = param.getMainBusinessScope();
        if (StringUtils.isEmpty(mainBusinessScope)) {
            return StringUtils.EMPTY;
        }
        if (mainBusinessScope.equals("其他")) {
            return param.getMainBusinessScopeExtra();
        }
        return mainBusinessScope;
    }

}
